/*
 * DropSourceImpl.cpp
 *
 *  Created on: 2012-9-2
 *      Author: yangentao@gmail.com
 */

#include "DropSourceImpl.h"

DropSourceImpl::DropSourceImpl() {
	refCount = 1;
}
DropSourceImpl::~DropSourceImpl() {

}
HRESULT __stdcall DropSourceImpl::QueryInterface(REFIID riid, void **ppv) {
	*ppv = NULL;
	if (riid == IID_IUnknown || riid == IID_IDropSource) {
		*ppv = this;
		AddRef();
		return S_OK;
	} else {
		return E_NOINTERFACE;
	}

}
HRESULT __stdcall DropSourceImpl::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState) {
	if (fEsc) {
		return DRAGDROP_S_CANCEL ;
	}
	if (0==(grfKeyState & MK_LBUTTON)) {
		return DRAGDROP_S_DROP ;
	}
	return S_OK ;
}

HRESULT __stdcall DropSourceImpl::GiveFeedback(DWORD dwEffect) {
	return DRAGDROP_S_USEDEFAULTCURSORS ;
}
ULONG __stdcall DropSourceImpl::AddRef(void) {
	return InterlockedIncrement(&refCount);
}

ULONG __stdcall DropSourceImpl::Release(void) {
	LONG r = InterlockedDecrement(&refCount);
	if (r == 0) {
		delete this;
		return 0;
	} else {
		return r;
	}
}

IDropSource* CreateDropSource(){
	return new DropSourceImpl();
}
